@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />

@endsection

@section('html-body')
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">商品列表</a>
            <em></em>
        </div>
        @include('admin.common.goods-header')
        <div class="filter-box clearfix">

            <div class="sx">
                <input type="text" class="gg-ipt" style="width: 130px;height: 26px" placeholder="输入商品名称或编号" name="keyword" id="keyword" value="{{$keyword}}">
                <span style="margin-left: 5px;">一级分类
                    <select id="classify">
                        <option value="0">全部</option>
                        @foreach($classifies as $classify)
                            <option value="{{$classify->id}}" @if($classify_id == $classify->id)selected @endif>{{$classify->name}}</option>
                        @endforeach
                    </select>
                </span>
                <span style="margin-left: 5px;">二级分类
                    <select id="classify_two">
                        <option value="0">全部</option>
                        @foreach($classifies_two as $classify)
                            <option value="{{$classify->id}}" @if($classify_two_id == $classify->id)selected @endif>{{$classify->name}}</option>
                        @endforeach
                    </select>
                </span>
                <span style="margin-left: 5px;">
                    <button class="sx-btn" id="sx_btn">筛选</button>
                </span>
                <div class="fr">
                    <a class="addBtn" href="{{route("Admin.Home.goodsSet")}}">新增</a>
                </div>
            </div>




        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>商品编号</th>
                    <th>商品名称</th>
                    <th>市场价格</th>
                    <th>销售价格</th>
                    <th>商品封面</th>
                    <th>商品分类</th>
                    <th>商品状态</th>
{{--                    <th>是否推荐</th>--}}
                    <th>销售数量</th>
                    <th>商品链接</th>
                    <th>商品排序</th>
                    <th>商品轮播图</th>
{{--                    <th>商品详情图</th>--}}
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($goods) > 0)
                    @foreach($goods as $good)
                        <tr id="goods_{{$good->id}}">
                            <td>{{$good->id}}</td>
                            <td>{{$good->ssn}}</td>
                            <td>{{$good->name}}</td>
                            <td>{{$good->m_price}}</td>
                            <td>{{$good->s_price}}</td>
                            <td class="account-td" style="width: 5%;">
                                <span class="photo" style="border-radius: 100%;display:initial">
                                    @if($good->thumb_id != 0)
                                        <a target="_blank" href="{{$good->thumb_url}}" class="openimg" data-key="{{$good->thumb_id}}"><img src="{{$good->thumb_url}}" alt="{{$good->thumb_url}}"></a>
                                    @else
                                        <img src="{{url('images/default-avatar.png')}}" alt="">
                                    @endif
                                </span>
                            </td>
                            <td>{{$good->classify_name}}</td>
                            <td>@if($good->is_shop == 1)<span class="color4">上架</span> @else<span class="color3">下架</span> @endif</td>
{{--                            <td>@if($good->is_recommend == 1)推荐 @else 不推荐 @endif</td>--}}
                            <td>{{$good->sale_count}}</td>
                            <td><a href="javascript:void(0);" data-id="" style="color: #ef1414;" onclick="upPop('{{$good->link_url}}','{{$good->name}}')">查看链接</a>
                            </td>
                            <td>{{$good->sort}}</td>
                            <td><a href="{{route('Admin.Home.goodsBannerList')}}?id={{$good->id}}">前往设置</a></td>
{{--                            <td><a href="{{route('Admin.Home.goodsImgList')}}?id={{$good->id}}">前往设置</a></td>--}}
                            <td style="overflow: visible;">
                                <a class="color2" href="{{route("Admin.Home.goodsSet")}}?id={{$good->id}}">编辑</a> <span>|</span>
                                <a class="color2" href="{{route('Admin.Home.goodsCommentList')}}?goods_id={{$good->id}}" >评论</a> <span>|</span>
                                <a class="color2" href="{{route('Admin.Home.goodsSpuList')}}?goods_id={{$good->id}}" >属性</a> <span>|</span>
                                <a href="javascript:void(0);" class="del" data-id="{{$good->id}}">删除 </a>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
        <div class="pagelist" style="text-align: center;">
            <?php echo $goods->render(); ?>
        </div>
    </div>


    <div class="upPop-box">
        <div class="backdrop"></div>
        <div id="upPop" class="info-pop tixian">
            <input type="hidden" name="id" id="classifyid" value=""/>
            <a class="close" href="javascript:void(0);"></a>
            <h3 id="title"></h3>
            <div class="fill-list">
             <h4 id="url"></h4>
            </div>

    {{--        <div class="fill-list">
                <h5>说明：复制链接以"/"开头，以数字为结束如"/pages/goodsDetail/main?id=27"</h5>
            </div>--}}
        </div>
    </div>
    <script>

        function upPop(obj1,obj2){
            $('#link_url').val(obj1);
            $("#url").html(obj1);
            $("#title").html(obj2+"链接");
            $('.upPop-box').upPop();

        }
        $(function(){



            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");

                noty({
                    text: '你确定要删除吗?',
                    buttons: [
                        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                            $noty.close();
                            $.ajax({
                                url:'{{route('Api.Admin.goods.delGoods')}}',
                                type:'post',
                                dataType:'json',
                                data:{id:id},
                                success:function(obj){
                                    if(obj.level == "success"){
                                        $("#goods_"+id).hide('slow');
                                    }else{
                                        noty({type:obj.level,text:obj.message,timeout:600});
                                    }
                                },
                                error:function(obj){
                                    console.log(obj);
                                }

                            });
                        }
                        },
                        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                            $noty.close();
                        }
                        }
                    ]
                });

            });
        });
        $('#sx_btn').click(function () {
            var keyword = $('#keyword').val();
            var classify_id = $('#classify option:selected').val();
            var classify_two = $('#classify_two option:selected').val();

            window.location.href = "{{route('Admin.Home.goodsList')}}?keyword=" + keyword + '&classify_id=' + classify_id + '&classify_two_id=' + classify_two;
        });
    </script>
@endsection